@@ -2,6 +2,7 @@ package com.example.skycode7.dao;

import com.example.skycode7.BEAN.AdminBean;
import com.example.skycode7.utill.DBConnection;
import com.example.skycode7.utill.Time;

import java.sql.*;
import java.util.ArrayList;
@@ -33,14 +34,14 @@ public class AdminDao {
     */
    public int add(AdminBean news){
        Connection conn = db.getConn();//conn代表mysql的连接
        String sql = "insert into news values(null,?,?,?,?,)";//使用jdbc预处理对象添加
        String sql = "insert into admin values(null,?,?,?,?)";//使用jdbc预处理对象添加
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
            //将新闻数据对象中数据依次绑定到sql命令中
            ps.setString(1,news.getAdminName());
            ps.setString(2,news.getAdminPwd());
            ps.setInt(3,news.getAdminType());
            ps.setString(4,news.getLastLonginTime());
            ps.setString(4, Time.grtDateTime());
            return ps.executeUpdate();//执行sql命令 完成数据插入
        } catch (SQLException e) {
            System.out.println("插入news表异常");
@@ -80,7 +81,7 @@ public class AdminDao {
            ps.setString(1,news.getAdminName());
            ps.setString(2,news.getAdminPwd());
            ps.setInt(3,news.getAdminType());
            ps.setString(4,news.getLastLonginTime());
            ps.setString(4,Time.grtDateTime());
            ps.setInt(5,news.getAdminID());
            return ps.executeUpdate();//执行sql命令 完成数据插入
        } catch (SQLException e) {
@@ -96,7 +97,7 @@ public class AdminDao {
     */
    public List<AdminBean> getlist(int page){
        Connection conn = db.getConn();
        String sql = "select * from news limit ?,?";//第一个开始的行数 第二个是查询现实的条数
        String sql = "select * from admin limit ?,?";//第一个开始的行数 第二个是查询现实的条数
        List<AdminBean> list = new ArrayList<>();
        try {
            PreparedStatement ps = conn.prepareStatement(sql);
@@ -106,11 +107,11 @@ public class AdminDao {
            ResultSet rs =ps.executeQuery();//rs数据查询结果集 全部是字符串
            while (rs.next()){
                AdminBean admin = new AdminBean();//每轮循环声明一个新闻对象
                admin.setAdminID(rs.getInt("AdminId"));//rs获取该行新闻ID 通过新闻对象封装方法设置新闻值
                admin.setAdminID(rs.getInt("AdminID"));//rs获取该行新闻ID 通过新闻对象封装方法设置新闻值
                admin.setAdminName(rs.getString("AdminName"));
                admin.setAdminPwd(rs.getString("AdminPwd"));
                admin.setAdminType(rs.getInt("AdminType"));
                admin.setLastLonginTime(rs.getNString("LastLonginTime"));
                admin.setLastLonginTime(rs.getString("LastLoginTime"));
                list.add(admin);//将设置好的新闻对象放入list中
            }
        } catch (SQLException e) {
@@ -118,4 +119,18 @@ public class AdminDao {
        }
        return list;//异常情况返回空集合
    }
    public int count() {
        Connection conn = db.getConn();
        String sql = "select count(*) from news";
        try {
            Statement statement = conn.createStatement();
            ResultSet rs = statement.executeQuery(sql);
            if (rs.next()) {
                return rs.getInt(1);
            }
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
        return 0;
    }
}